package com.mc.moring.util;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;


/**
 * Created by goldze on 2017/5/14.
 */
public final class ToastUtils {

    private static Toast toast;

    public static void showShort(Context context, String text) {
        show(context, text, Toast.LENGTH_LONG, false);
    }

    public static void showShort(Context context, String text, boolean mid) {
        show(context, text, Toast.LENGTH_LONG, mid);
    }


    public static void showLong(Context context, String text) {
        show(context, text, Toast.LENGTH_LONG, false);
    }

    public static void showLong(Context context, String text, boolean mid) {
        show(context, text, Toast.LENGTH_LONG, mid);
    }

    private static void show(Context context, String text, int time, boolean mid) {
        if (toast == null) {
            if (mid) {
                toast = Toast.makeText(context, text, time);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                toast = Toast.makeText(context, text, time);
            }
        } else {
            if (mid) {
                toast.setText(text);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                toast.setText(text);
            }
        }
        toast.show();
    }
}